package com.zdsoft.wms.controller;

import com.zdsoft.wms.auth.CheckAuthorization;
import com.zdsoft.wms.auth.CheckLogin;
import com.zdsoft.wms.bean.User;
import com.zdsoft.wms.common.ServerResponse;
import com.zdsoft.wms.feign.UserFeignClient;
import com.zdsoft.wms.service.UserService;
import com.zdsoft.wms.utils.CookieUtil;
import com.zdsoft.wms.utils.JwtOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sqd")
public class SqdController {

    private static  String SERVER_NAME="user-center";
    @Value("${server.port}")
    private  String port;
    @Autowired
    UserFeignClient userFeignClient;

    @Autowired
    RestTemplate restTemplate;

    @CheckAuthorization("TEACHER")
    @GetMapping("/serinfo/{serstation}")
    public ServerResponse  findAllBySerstationId(@PathVariable("serstation") int serstationId){
        ServerResponse  serverResponse=  restTemplate.getForObject("http://"
                + SERVER_NAME+ "/user/serinfo/"+serstationId, ServerResponse.class);
        return  userFeignClient.findAllBySerstationId(serstationId);
    }

    @CheckLogin
    @GetMapping("/info/{id}")
    public ServerResponse  findInfoById(@PathVariable("id") int id){
        return  userFeignClient.findInfoById(id);
    }

    @GetMapping("/port")
    public String getport(){
      return port;
    }
}
